

package com.custom.serde;


import com.custom.source.ClinkSourceSplit;
import lombok.val;
import org.apache.flink.core.io.SimpleVersionedSerializer;

import java.io.IOException;

/**
 * 分片序列化类
 *
 * @param <splitT> 分片类型
 */
public class DefaultSplitSerializer<splitT extends ClinkSourceSplit> implements SimpleVersionedSerializer<splitT> {

    @Override
    public int getVersion() {
        return 0;
    }

    @Override
    public byte[] serialize(splitT obj) {
        return SerializerUtils.serialize(obj);
    }

    @Override
    public splitT deserialize(int version, byte[] serialized) throws IOException {
        if (version != getVersion()) {
            throw new IOException("Unrecognized version: " + version);
        }
        @SuppressWarnings("unchecked")
        val split = (splitT) SerializerUtils.deserialize(serialized);
        return split;
    }
}
